package com.smartwebee.android.blespp.blockly.dialog;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;

import com.smartwebee.android.blespp.R;
import com.smartwebee.android.blespp.databinding.DialogTipsBinding;

/**
 * 包含两个按钮，标题和内容文案的弹框
 */
public class TipsDialog extends CenterDialogFragment<DialogTipsBinding> {

    public static String TAG = "TipsDialog";
    private String leftStr;
    private String rightStr;
    private String title;
    private String content;
    private ClickEvent clickEvent;

    @Override
    public void onStart() {
        super.onStart();
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        int adDialogWidth = (int) (dm.widthPixels * 0.37);

        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//宽度全屏的关键
        getDialog().getWindow().setLayout(adDialogWidth, getDialog().getWindow().getAttributes().height);
        getDialog().getWindow().setGravity(Gravity.CENTER);
    }

    @Override
    protected int setLayout() {
        return R.layout.dialog_tips;
    }

    @Override
    protected void initView(DialogTipsBinding binding) {
        if (!TextUtils.isEmpty(leftStr)) {
            binding.tvLeft.setText(leftStr);
        }
        if (!TextUtils.isEmpty(rightStr)) {
            binding.tvRight.setText(rightStr);
        }
        if (!TextUtils.isEmpty(title)) {
            binding.tvTitle.setText(title);
        }
        if (!TextUtils.isEmpty(content)) {
            binding.tvContent.setText(content);
        }
        binding.tvLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (clickEvent != null) {
                    clickEvent.clickLeft();
                }
                dismiss();
            }
        });
        binding.tvRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (clickEvent != null) {
                    clickEvent.clickRight();
                }
                dismiss();
            }
        });

    }

    public interface ClickEvent {
        void clickLeft();
        void clickRight();
    }

    public String getLeftStr() {
        return leftStr;
    }

    public void setLeftStr(String leftStr) {
        this.leftStr = leftStr;
    }

    public String getRightStr() {
        return rightStr;
    }

    public void setRightStr(String rightStr) {
        this.rightStr = rightStr;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public ClickEvent getClickEvent() {
        return clickEvent;
    }

    public void setClickEvent(ClickEvent clickEvent) {
        this.clickEvent = clickEvent;
    }
}
